﻿<UserControl
    x:Class="Berico.SnagL.Infrastructure.Modularity.ToolPanel.ClusteringToolPanelItemExtensionView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.SL4"    
    xmlns:internal="clr-namespace:Berico.SnagL.Infrastructure.Controls"
    xmlns:bericoControls="clr-namespace:Berico.Windows.Controls;assembly=Berico.Windows.Controls"
    mc:Ignorable="d"
    d:DesignHeight="100" d:DesignWidth="200">

    <UserControl.Resources>
        
        <Style x:Key="ClusterButtonStyle" TargetType="Button">
            <Setter Property="IsEnabled" Value="true"/>
            <Setter Property="IsTabStop" Value="true"/>
            <Setter Property="Background" Value="#FFA9A9A9"/>
            <Setter Property="Foreground" Value="#FF000000"/>
            <Setter Property="MinWidth" Value="5"/>
            <Setter Property="MinHeight" Value="5"/>
            <Setter Property="Margin" Value="0"/>
            <Setter Property="HorizontalAlignment" Value="Left" />
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Cursor" Value="Hand"/>
            <!--<Setter Property="TextAlignment" Value="Left"/>
            <Setter Property="TextWrapping" Value="NoWrap"/>-->
            <!--<Setter Property="FontWeight" Value="Bold" />-->
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Grid>
                            <Grid.Resources>
                                <LinearGradientBrush x:Key="ButtonBorderGradient" EndPoint="0.5,1" StartPoint="0.5,0">
                                    <GradientStop Color="#FF4F4F4F"/>
                                    <GradientStop Color="#FF464646" Offset="1"/>
                                </LinearGradientBrush>
                                <SolidColorBrush x:Key="DisabledBrush" Color="#A5FFFFFF"/>
                            </Grid.Resources>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal">
                                    </VisualState>
                                    <VisualState x:Name="MouseOver">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundMouseOver" Storyboard.TargetProperty="Visibility" Duration="0">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Visible</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGradientMouseOver" Storyboard.TargetProperty="Visibility" Duration="0">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Visible</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Normal_Image" Storyboard.TargetProperty="Visibility" Duration="0">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Collapsed</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Hover_Image" Storyboard.TargetProperty="Visibility" Duration="0">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Visible</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Border x:Name="Background" Visibility="Visible" BorderBrush="{StaticResource ButtonBorderGradient}" BorderThickness="1" CornerRadius="5,5,5,5" Margin="1" />
                            <Border x:Name="BackgroundMouseOver" Visibility="Collapsed" BorderBrush="Transparent" BorderThickness="1" CornerRadius="5,5,5,5" Background="#FFA9A9A9" Margin="1" />
                            <Border x:Name="BackgroundGradientMouseOver" Visibility="Collapsed" BorderBrush="{StaticResource ButtonBorderGradient}" BorderThickness="1" CornerRadius="5,5,5,5" Margin="1">
                                <Border.Background>
                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                        <GradientStop Color="#FCFFFFFF"/>
                                        <GradientStop Color="#4CFFFFFF" Offset="1"/>
                                    </LinearGradientBrush>
                                </Border.Background>
                            </Border>
                            <ContentPresenter x:Name="Content" Margin="4,5,4,4"  Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" />
                            <Path x:Name="DisabledVisual" Fill="{StaticResource DisabledBrush}" Opacity="0" StrokeMiterLimit="1.000000" Data="F1 M 130.916504,120.166992 C 130.916504,126.793945 125.543457,132.166992 118.916504,132.166992 L 0.500000,132.166992 L 0.500000,0.500000 L 118.916504,0.500000 C 125.543457,0.500000 130.916504,5.872559 130.916504,12.500000 L 130.916504,120.166992 Z" Stretch="Fill" />
                            <Image x:Name="Normal_Image" Margin="4" Visibility="Visible" Height="Auto" Width="Auto" VerticalAlignment="Center" HorizontalAlignment="Center" Source="/Berico.SnagL;component/Resources/Icons/SnagL/Execute.png" />
                            <Image x:Name="Hover_Image" Margin="4" Visibility="Collapsed" Height="Auto" Width="Auto" VerticalAlignment="Center" HorizontalAlignment="Center" Source="/Berico.SnagL;component/Resources/Icons/SnagL/Execute_Hover.png" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="CriterionListBoxStyle" TargetType="ListBoxItem">
            <Setter Property="Padding" Value="1"/>
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
            <Setter Property="VerticalContentAlignment" Value="Top"/>
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="TabNavigation" Value="Local"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBoxItem">
                        <Grid Background="{TemplateBinding Background}">
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="MouseOver">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0" To=".35" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="fillColor"/>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Disabled">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0" To=".55" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="contentPresenter"/>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="SelectionStates">
                                    <VisualState x:Name="Unselected"/>
                                    <VisualState x:Name="Selected">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0" To=".75" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="fillColor2"/>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="FocusStates">
                                    <VisualState x:Name="Focused">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Visibility" Storyboard.TargetName="FocusVisualElement">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Visible</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Unfocused"/>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Rectangle x:Name="fillColor" Fill="#B24A75A9" IsHitTestVisible="False" Opacity="0" RadiusY="1" RadiusX="1"/>
                            <Rectangle x:Name="fillColor2" Fill="#B24A75A9" IsHitTestVisible="False" Opacity="0" RadiusY="1" RadiusX="1"/>
                            <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}"/>
                            <Rectangle x:Name="FocusVisualElement" RadiusY="1" RadiusX="1" Stroke="#B24A75A9" StrokeThickness="2" Visibility="Collapsed"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    
    <Grid x:Name="LayoutRoot" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        
        <!-- Defines Control menu -->
        <Border Grid.Row="0" BorderBrush="#FF8E8E8E" BorderThickness="1" Height="Auto" Width="Auto" HorizontalAlignment="Stretch">
            <Border.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFF0F0F0"/>
                    <GradientStop Color="#FF8C8C8C" Offset="1"/>
                </LinearGradientBrush>
            </Border.Background>

            <Grid Margin="5,1,5,1" >
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="8*" />
                    <ColumnDefinition Width="2*" />
                </Grid.ColumnDefinitions>

                <!-- Mode Buttons -->
                <StackPanel Grid.Column="0" Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center" >
                    <RadioButton GroupName="ClusteringMode" Content="Simple  " Margin="5,0,5,0" IsChecked="True" Command="{Binding SimpleSelectedCommand}" />
                    <RadioButton GroupName="ClusteringMode" Content="Advanced" Margin="5,0,5,0" Command="{Binding AdvancedSelectedCommand}" />
                </StackPanel>
                
                <!-- Cluster Command button -->
                <Button Grid.Column="1" Grid.Row="0" Style="{StaticResource ClusterButtonStyle}" IsEnabled="{Binding ClusteringEnabled}" Command="{Binding ClusterCommand}" Height="30" Width="30" HorizontalAlignment="Right" VerticalAlignment="Center" />
                
                <!-- Threshold Slider -->
                <!--<TextBlock Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Text="Similarity Threshold" VerticalAlignment="Top" HorizontalAlignment="Center"  />-->
                <bericoControls:Slider x:Name="FuzzySlider" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" IsEnabled="{Binding IsThresholdSliderEnabled}" Margin="10,10,10,10" Minimum="1" Maximum="{Binding NumberOfThresholds, FallbackValue=5}" SmallChange="1" LargeChange="1" IsSnapToTickEnabled="True" TickFrequency="1" TickLocation="Bottom" Value="{Binding SimilarityThresholdValue, Mode=TwoWay, FallbackValue=1}">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="ValueChanged">
                            <cmd:EventToCommand Command="{Binding ThresholdChangedCommand}" PassEventArgsToCommand="True"/>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </bericoControls:Slider>
            </Grid>
        </Border>

        <!-- Containter for AttributeSimilarityPanel controls -->
        <ListBox Grid.Row="1" ItemsSource="{Binding SimilarityCriteria}" BorderBrush="Black" SelectionMode="Single" SelectedItem="{Binding SelectedCriterion, Mode=TwoWay}" BorderThickness="1" HorizontalContentAlignment="Stretch" ItemContainerStyle="{StaticResource CriterionListBoxStyle}">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="SelectionChanged">
                    <cmd:EventToCommand Command="{Binding SelectionChangedCommand}" PassEventArgsToCommand="True"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <internal:AttributeSimilarityCriterion HorizontalContentAlignment="Stretch" />
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
    
</UserControl>
